<?php

namespace backend\models\download;
use Yii;
use yii\data\Pagination;

/**
 * This is the model class for table "edu_softcate".
 *
 * @property integer $softcate_id
 * @property string $softcate_name
 * @property integer $softcate_addtime
 * @property integer $softcate_updtime
 * @property integer $softcate_sort
 * @property integer $softcate_status
 */
class Softcate extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'edu_softcate';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            //[['softcate_name', 'softcate_addtime', 'softcate_updtime', 'softcate_status'], 'required'],
            [['softcate_name', 'softcate_sort', 'softcate_status'], 'required'],
            [['softcate_sort', 'softcate_status'], 'integer'],
            [['softcate_name'], 'string', 'max' => 50]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'softcate_id' => 'Softcate ID',
            'softcate_name' => '分类名称',
            'softcate_addtime' => 'Softcate Addtime',
            'softcate_updtime' => 'Softcate Updtime',
            'softcate_sort' => '分类排序',
            'softcate_status' => '分类状态',
        ];
    }

	/**
	 *软件分类 分类接收入库
	 */
	 public function Cateadd($data = array()) {			
        $this->load(Yii::$app->request->post());
		$this->softcate_addtime = time();
		$this->softcate_updtime = time();
        return $this->save();	
	 }

	/**
	 *软件分类 分类输出列表
	 */
	 public function Catelist() {			
        //return $this->find()->all();
		$query = Softcate::find();
		$countQuery = clone $query;
		$pages = new Pagination(['totalCount' => $countQuery->count(),'pageSize' => '8']);
		$models = $query->offset($pages->offset)
		->orderby('softcate_updtime desc')
        ->limit($pages->limit)
        ->all();
		return ['pages' => $pages, 'models' => $models];
	 }

	 /**
	  * 软件分类 分类查询
	  */
	 public function Cateupd () {
		return $this -> find()
			  -> where(['softcate_id' => Yii::$app -> request -> get('id')])->asArray()
			  -> one();
	 }

	 /**
	  * 软件分类 分类修改
	  */
	 public function Cateupdate () {
		$cate = $this -> findOne(Yii::$app->request->get('id'));
		$cate->load(Yii::$app->request->post());
		$cate->softcate_updtime = time();
		return $cate->save();
	 }

	 /**
	  * 软件分类 分类删除
	  */
	 public function Cateupdel () {
		$id = Yii::$app->request->post();
		return $this->deleteAll(['softcate_id'=>$id['delid']]);
	 }


}
